

require('../css/bootstrap.css');

//require('../css/allcommon.css');

require('../css/navbar.css');



require('jquery');



window.bingmap = {};
window.smallmap = {};
var zoominflag = false;
var searchManager;

function loadScript(url, callback){
            var script = document.createElement("script")
            script.type = "text/javascript";
            if (script.readyState){  //IE
                script.onreadystatechange = function(){
                    if (script.readyState == "loaded" || script.readyState == "complete"){
                        script.onreadystatechange = null;
                        callback();
                    }
                };
            } else {  //Others
                script.onload = function(){ callback(); };
            }
            script.src = url;
            document.getElementsByTagName("head")[0].appendChild(script);
}



//&key=AIzaSyDCA0QevQrnfxYCoJI-O0dnoeX6Bi8vU6g
window.bingmapsload = function(){



var initcenter = new Microsoft.Maps.Location(40.768695,-73.982007);

bingmap = new Microsoft.Maps.Map('#map', {
            credentials: 'Aibiz4eYpqkLQlxfqQRVBaxB_DD9jpFx1Efp2XrLuRLlowJ1792eHlfXdJYeUTAo',

            center: initcenter,
             mapTypeId: Microsoft.Maps.MapTypeId.aerial,

                zoom: 14
            });
var pushpin = new Microsoft.Maps.Pushpin(initcenter);

bingmap.entities.push(pushpin);




        Microsoft.Maps.loadModule('Microsoft.Maps.AutoSuggest', function () {
            var options = {
                map: bingmap,
            };
            var manager = new Microsoft.Maps.AutosuggestManager(options);

            manager.attachAutosuggest('#pac-input','#search-form',selectedSuggestion);
        });



        Microsoft.Maps.loadModule('Microsoft.Maps.Search', function () {

            console.log('search loaed');
            searchManager = new Microsoft.Maps.Search.SearchManager(map);
        });


function selectedSuggestion(suggestionResult) {



            bingmap.entities.clear();
            if(!suggestionResult.location){

                return;
            }else{
                var pushpin = new Microsoft.Maps.Pushpin(suggestionResult.location);
                bingmap.entities.push(pushpin);

               bingmap.setView({ center: suggestionResult.location });

            }


}

}










loadScript('http://www.bing.com/api/maps/mapcontrol?callback=bingmapsload&branch=experimenta',function(){
    //initAutocomplete();
    //bingmapsload();
    console.log('123');
    //bingmapsloadlocal();

});


    $("#search-form").submit(function(){
        search();
        return false;
    });

    $("#searchbtn").click(function(){
        search();
        return false;
    });



function search(){
    geocodeQuery(bingmap,$("#pac-input").val());
}

